package com.lrkj.waitress.controller;

import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.Api;
import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.lrkj.common.annotation.Log;
import com.lrkj.common.core.controller.BaseController;
import com.lrkj.common.core.domain.AjaxResult;
import com.lrkj.common.enums.BusinessType;
import com.lrkj.waitress.domain.CruiserTask;
import com.lrkj.waitress.service.ICruiserTaskService;
import com.lrkj.common.utils.poi.ExcelUtil;
import com.lrkj.common.core.page.TableDataInfo;

/**
 * 巡逻任务Controller
 *
 * @author yajun_ren
 * @date 2022-03-23
 */
@RestController
@RequestMapping("/waitress/CruiserTask")
@Api(tags = "巡逻任务")
public class CruiserTaskController extends BaseController
{
    @Autowired
    private ICruiserTaskService cruiserTaskService;

    /**
     * 查询巡逻任务列表
     */
    @ApiOperation(value = "查询巡逻任务列表", notes = "查询巡逻任务列表")
    @PreAuthorize("@ss.hasPermi('waitress:CruiserTask:list')")
    @GetMapping("/list")
    public TableDataInfo list(CruiserTask cruiserTask)
    {
        startPage();
        this.changeParameter(cruiserTask.getParams());
        List<CruiserTask> list = cruiserTaskService.selectCruiserTaskList(cruiserTask);
        return getDataTable(list);
    }

    /**
     * 导出巡逻任务列表
     */
	@ApiOperation(value = "导出巡逻任务列表", notes = "导出巡逻任务列表")
    @PreAuthorize("@ss.hasPermi('waitress:CruiserTask:export')")
    @Log(title = "巡逻任务", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(CruiserTask cruiserTask)
    {
        List<CruiserTask> list = cruiserTaskService.selectCruiserTaskList(cruiserTask);
        ExcelUtil<CruiserTask> util = new ExcelUtil<CruiserTask>(CruiserTask.class);
        return util.exportExcel(list, "巡逻任务数据");
    }

    /**
     * 获取巡逻任务详细信息
     */
	@ApiOperation(value = "获取巡逻任务详细信息", notes = "获取巡逻任务详细信息")
    @PreAuthorize("@ss.hasPermi('waitress:CruiserTask:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return AjaxResult.success(cruiserTaskService.selectCruiserTaskById(id));
    }

    /**
     * 新增巡逻任务
     */
    @ApiOperation(value = "新增巡逻任务", notes = "新增巡逻任务")
    @PreAuthorize("@ss.hasPermi('waitress:CruiserTask:add')")
    @Log(title = "巡逻任务", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CruiserTask cruiserTask)
    {
        return toAjax(cruiserTaskService.insertCruiserTask(cruiserTask));
    }

    /**
     * 修改巡逻任务
     */
    @ApiOperation(value = "修改巡逻任务", notes = "修改巡逻任务")
    @PreAuthorize("@ss.hasPermi('waitress:CruiserTask:edit')")
    @Log(title = "巡逻任务", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CruiserTask cruiserTask)
    {
        return toAjax(cruiserTaskService.updateCruiserTask(cruiserTask));
    }


    /**
     * 完成巡检任务
     * @param cruiserTask
     * @return
     */
    @PreAuthorize("@ss.hasPermi('waitress:CruiserTask:updCruiserOff')")
    @PutMapping("/updCruiserOff")
    public AjaxResult updCruiserOff(@RequestBody CruiserTask cruiserTask){
        return  toAjax(cruiserTaskService.updCruiserOff(cruiserTask));
    }

    /**
     * 删除巡逻任务
     */
    @ApiOperation(value = "删除巡逻任务", notes = "删除巡逻任务")
    @PreAuthorize("@ss.hasPermi('waitress:CruiserTask:remove')")
    @Log(title = "巡逻任务", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(cruiserTaskService.deleteCruiserTaskByIds(ids));
    }
}
